home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / oocs / cservera.cls < prev    next >
Text File  |  1999-09-06  |  5KB  |  179 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "cServerActions"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. ' access to the methods of the cFileActions class
  13. Dim File As cFIleActions
  14. ' access to the methods of the cSysInfo class
  15. Dim Sys As cSysInfo
  16.  
  17. ' --- Events
  18. Public Event ConnectionClosed()
  19. Public Event RequestedID(Accepted As Boolean)
  20.  
  21.  
  22. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  23. '
  24. '  P U B L I C   M E T H O D S
  25. '
  26. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  27.  
  28.  
  29. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  30. Sub InitTCP(Port As Long, Server As Winsock)
  31.     ' connect to the port
  32.     Server.LocalPort = Port
  33.     ' Listen for incoming data
  34.     Server.Listen
  35. End Sub
  36.  
  37.  
  38.  
  39. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  40. Sub HandleIncomingData(sIncoming As String, Server As Winsock, SrvForm As Form)
  41.     '
  42.     Dim sCommand As String
  43.     Dim sIncomingData As String
  44.     
  45.     '--- when a command is sent the first seperater is a comma, the default.
  46.     '--- Therefore "sDivider" is not set.
  47.     
  48.     ' Extract the command from the Left
  49.     ' of the comma (default divider)
  50.     sCommand = EvalData(sIncoming, 1)
  51.     ' extract the data being sent from the
  52.     ' right of the comma (default divider)
  53.     sIncomingData = EvalData(sIncoming, 2)
  54.     
  55.     ' decide what command has been issued
  56.     Select Case sCommand
  57.          Case "Msg"
  58.             File.DisplayMsg sIncomingData
  59.          Case "SysInfo"
  60.             Sys.GetSysInfo
  61.          Case "GetFilePaths"
  62.             File.GatherFiles sIncomingData, SrvForm
  63.     End Select
  64.     
  65. End Sub
  66.  
  67.  
  68.     
  69. Sub Closed(Server As Winsock)
  70.     'Socket got a close call so close it if it's not already closed
  71.     If Server.State <> sckClosed Then Server.Close
  72.     'Call the form load event to reset all paramteres
  73.     Set File = Nothing
  74.     Set Sys = Nothing
  75.     RaiseEvent ConnectionClosed
  76. End Sub
  77.  
  78.  
  79. Sub ConnectReq(ByVal requestID As Long, Server As Winsock)
  80.      On Error GoTo IDERROR
  81.      If Server.State <> sckClosed Then Server.Close ' close Connection
  82.      Server.Accept requestID                        'Make the connection
  83.      
  84.      
  85.      RaiseEvent RequestedID(True)
  86.      Exit Sub
  87.      
  88. IDERROR:
  89.      RaiseEvent RequestedID(False)
  90. End Sub
  91.  
  92.  
  93.  
  94.  
  95.  
  96. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  97. '======================================================================
  98. ' (EvalData Function)
  99. '
  100. '  Purpose - Extract data from a given string, to the right or left
  101. '            of a specified character.
  102. '
  103. '  Parameters:
  104. '     sIncoming - The String you want to extract data from.
  105. '     iRtLt     - Extract from the Left, 1.
  106. '                 Extract from the right, 2.
  107. '     sDivider  - The character that seperates the data in
  108. '                 the string. <default = ",">
  109. '
  110. '  Returns:
  111. '     (type)String
  112. '     Returns the data to the right or left of strDivider.
  113. '======================================================================
  114.              
  115.  
  116. Private Function EvalData(sIncoming As String, iRtLt As Integer, _
  117.                   Optional sDivider As String) As String
  118.    Dim i As Integer
  119.    Dim TempStr As String
  120.    ' Storage for the current Divider
  121.    Dim sSplit As String
  122.    
  123.    ' the current character used to divide the data
  124.    If sDivider = "" Then
  125.       sSplit = ","
  126.    Else
  127.       sSplit = sDivider
  128.    End If
  129.    
  130.    ' getting the right or left?
  131.    Select Case iRtLt
  132.         
  133.       Case 1
  134.           ' remove the data to the Left of the Current Divider
  135.           For i = 0 To Len(sIncoming)
  136.             TempStr = Left(sIncoming, i)
  137.             
  138.             If Right(TempStr, 1) = sSplit Then
  139.               EvalData = Left(TempStr, Len(TempStr) - 1)
  140.               Exit Function
  141.             End If
  142.           Next
  143.           
  144.       Case 2
  145.           ' remove the data to the Right of the Current Divider
  146.           For i = 0 To Len(sIncoming)
  147.             TempStr = Right(sIncoming, i)
  148.             
  149.             If Left(TempStr, 1) = sSplit Then
  150.               EvalData = Right(TempStr, Len(TempStr) - 1)
  151.               Exit Function
  152.             End If
  153.           Next
  154.    End Select
  155.    
  156. End Function
  157.  
  158.  
  159.  
  160. Private Sub Class_Initialize()
  161.     ' create objects to access the file and system
  162.     ' retrieval methods
  163.     Set File = New cFIleActions
  164.     Set Sys = New cSysInfo
  165. End Sub
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.